package com.bobo.web.provider.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@Configuration
public class ThreadPoolConfig {
    /**
     * 表单完整度、异常报警统计
     * @return
     */
    @Bean("BasketballThreadPool")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(20);
        executor.setMaxPoolSize(40);
        executor.setQueueCapacity(400);
        executor.setKeepAliveSeconds(60);
        /**
         * 默认false 线程即使达到销毁时间也不销毁，新请求使用已有的线程
         * true 线程达到销毁时间销毁，新请求重新开辟线程
         */
        executor.setAllowCoreThreadTimeOut(false);
        executor.setThreadNamePrefix("formEditCompleteWarn-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return executor;
    }
}
